﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
   public class Ctbl_News_Lang :IData<tbl_News_Lang>
    {
        public Ctbl_News_Lang(String myconnecString) : base(myconnecString) { }


        

        public override List<tbl_News_Lang> GetAll(tbl_News_Lang item)
        {
            throw new NotImplementedException();
        }

        public override tbl_News_Lang GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdNewLang == Convert.ToInt32(id));
        }

        public override tbl_News_Lang GetItem(IDataReader dr)
        {
            tbl_News_Lang obj = new tbl_News_Lang();
            obj.BodyNew = Convert.ToString(dr[tbl_News_Lang.c_bodyNew]);
            obj.IdLang = Convert.ToInt32(dr[tbl_News_Lang.c_idLang]);
            obj.IdNew = Convert.ToInt32(dr[tbl_News_Lang.c_idNew]);
            obj.IdNewLang = Convert.ToInt32(dr[tbl_News_Lang.c_idNewLang]);
            obj.IntroNew = Convert.ToString(dr[tbl_News_Lang.c_introNew]);
            obj.TitleNew = Convert.ToString(dr[tbl_News_Lang.c_titleNew]);
            return obj;
        }

        public override List<tbl_News_Lang> GetAll()
        {
            String strSQL = "select * from " +tbl_News_Lang.b_tbl_News_Lang;
            return GetAll(strSQL, CommandType.Text);
        }

        protected override int InsertOnSubmit(tbl_News_Lang item, int t)
        {
            return connec.ExecuteNonQuery("proNewsLang", CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@"+tbl_News_Lang.c_bodyNew,item.BodyNew),new SqlParameter("@"+tbl_News_Lang.c_idLang,item.IdLang),
                new SqlParameter("@"+tbl_News_Lang.c_idNew,item.IdNew),new SqlParameter("@"+tbl_News_Lang.c_idNewLang,item.IdNewLang),
                new SqlParameter("@"+tbl_News_Lang.c_introNew,item.IntroNew),new SqlParameter("@"+tbl_News_Lang.c_titleNew,item.TitleNew));

        }
    }
}
